package lsf.itcast.dao;

import lsf.itcast.domain.Permission;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface PermissionDao {
    //根据角色Id查询权限
    @Select("select * from permission where id in (select permissionId from role_permission where roleId =#{roleId})")
    List<Permission> findByRoleId(String roleId);

    //查询所有角色信息
    @Select("select * from permission ")
    List<Permission> findAll();

    //新增权限
    @Insert("insert into permission(permissionName,url) values(#{permissionName},#{url})")
    void save(Permission permission);

    //根据roleId查询中间表，排除已经关联的roleId跟permissionId
    @Select("select * from permission where id not in (select permissionId from role_permission where roleId =#{roleId})")
    List<Permission> findOtherPermission(String roleId);
}
